﻿//操作数组 
Array.prototype.indexOf = function (val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};
Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

Array.prototype.min = function () {
    var min = this[0];
    var len = this.length;
    for (var i = 1; i < len; i++) {
        if (this[i] < min) {
            min = this[i];
        }
    }
    return min;
}
Array.prototype.max = function () {
    var max = this[0];
    var len = this.length;
    for (var i = 1; i < len; i++) {
        if (this[i] > max) {
            max = this[i];
        }
    }
    return max;
}

//分割字符串
function Split(str, splits) {
    var result = new Array();
    var lastIndex = 0;
    var i = 0;
    // debugger;
    while (i <= str.length) {
        var curchar = str.substr(i, 1);
        if (splits.indexOf(curchar) > -1) {
            var curtmp = str.substring(lastIndex, i + 1);
            result.push(curtmp);
            lastIndex = i + 1;
        }
        i++;
    }
    curtmp = str.substring(lastIndex, i + 1);
    result.push(curtmp);
    return result;
}
//获取当前可视区域高度
function GetInnerHeight() {
    var h = (window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight));
    return h;
}
//获取当前可视区域长度
function GetInnerWidth() {
    var de = document.documentElement;
    return window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
}

function request(strParame, url) {
    var args = new Object();
    var query = "";
    if (!url)
        query = location.search.substring(1); // Get query string
    else {
        var index = url.indexOf("?");
        query = url.substring(index + 1);
    }
    var pairs = query.split("&"); // Break at ampersand
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('='); // Look for "name=value"
        if (pos == -1) continue; // If not found, skip
        var argname = pairs[i].substring(0, pos); // Extract the name
        var value = pairs[i].substring(pos + 1); // Extract the value
        value = decodeURIComponent(value); // Decode it, if needed
        args[argname] = value; // Store as a property
    }
    return args[strParame]; // Return the object
}

function newGuid() {
    var guid = "";
    for (var i = 1; i <= 32; i++) {
        var n = Math.floor(Math.random() * 16.0).toString(16);
        guid += n;
        if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
            guid += "-";
    }
    return guid;
}
//在tab 页中打开页面.如果打不开则以窗口的形式弹出
function OpenUrlOnTab(url, title, fire, option) {
    if (!title || title == "")
        title = "窗口--";
    var defaultOption = { type: "tab", width: 600, height: 400 };
    defaultOption = $.extend(defaultOption, option);
    if (defaultOption.type == "div" && typeof ($().dialog) == "undefined")
        defaultOption.type = "tab";
    if (window.parent && window.parent != null && window.parent != window && defaultOption.type == "tab") {
        window.parent.AddTab(fire, title, url);
    } else if (defaultOption.type == "div") {
        var frmid = "dlg_" + newGuid();
        if (typeof ($().dialog) != "undefined") {
            var html = "<div id='" + frmid + "' title='" + title + "' style='width:"
            + defaultOption.width + "px;height:"
             + defaultOption.height + "px;'><iframe SCROLLING='auto' class='currentiframe' src='" + url + "' style='width:100%;height:100%;border:0;' frameborder=0></iframe></div>";
            $("body").append(html);
            try {
                $("#" + frmid).dialog({ left: 50, top: 50, modal: true,
                    buttons: [
                { text: "保存", handler: function () {
                    var ifrm = $(".currentiframe", $("#" + frmid))[0];
                    if (ifrm) {
                        if (ifrm.contentWindow.Save) {
                            ifrm.contentWindow.Save();
                        }
                    }
                }
                }, { text: "保存并关闭", handler: function () {
                    var ifrm = $(".currentiframe", $("#" + frmid))[0];
                    if (ifrm) {
                        if (ifrm.contentWindow.Save) {
                            ifrm.contentWindow.Save(function () {
                                $(ifrm).remove();
                                $('#' + frmid).dialog('close');
                            })
                        }
                    }
                }
                }, { text: "关闭", handler: function () {
                    $(".currentiframe", $("#" + frmid)).remove();
                    $('#' + frmid).dialog('close');
                }
                }
                ]
                });
            }
            catch (e) {

            }
        }
    }
    else if (defaultOption.type == "redirect") {
        location.href = url + "&url=" + encodeURI(location.href) + "&rnd=" + Math.random();
    }
    else
        window.open(url);
}
/*
Default页面用JS
*/